<?php
 
// this file must be stored in:
// protected/components/WebUser.php
 
class WebUser extends CWebUser {
 
  // Store model to not repeat query.
  private $_model;
 
  // Return first name.
  // access it by Yii::app()->user->first_name
  function getFullname(){
    $user = $this->loadUser(Yii::app()->user->id);
    return $user->fullname;
  }
  // This is a function that checks the field 'role'
  // in the User model to be equal to 1, that means it's admin
  // access it by Yii::app()->user->isAdmin()
  function getRole(){
    $user = $this->loadUser(Yii::app()->user->id);
    $role='';
	switch (intval($user->role)) {
		case 0:
			$role='superadmin';
			break;
		case 1:
			$role='admin';
			break;
		case 2:
			$role='manager';
			break;
		case 3:
			$role='filmmanager';
			break;
		case 4:
			$role='clipmanager';
			break;
		default:
			$role='';
		break;
	}
    return $role;
  }
  function getEmail(){
    $user = $this->loadUser(Yii::app()->user->id);
    return $user->email;
  }
  // Load user model.
  protected function loadUser($id=null)
    {
        if($this->_model===null)
        {
        	$this->_model=new Users;
            if($id!==null)
                $this->_model=Users::model()->findByPk($id);
        }
        return $this->_model;
    }
}
?>